<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="属性名称">
              <j-input placeholder="请输入属性名称" v-model="queryParam.propName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="类型">
              <j-dict-select-tag placeholder="请选择类型" v-model="queryParam.propType" dictCode="prop_type" />
            </a-form-item>
          </a-col>
          <a-col :xl="3" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-select default-value="1" v-model="queryParam.status">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="1">启用</a-select-option>
                <a-select-option value="0">禁用</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a-switch v-model="record.status" @change="onChange(record)" size="small" />
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <data-property-modal ref="modalForm" @ok="modalFormOk"></data-property-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DataPropertyModal from './modules/DataPropertyModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'DataPropertyList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    DataPropertyModal,
  },
  data() {
    return {
      /* 排序参数 */
      isorter: {
        column: 'id',
        order: 'desc',
      },
      description: '数据属性管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '属性ID',
          align: 'center',
          dataIndex: 'id',
          width: 160,
        },
        {
          title: '属性编号',
          align: 'center',
          dataIndex: 'propNo',
        },
        {
          title: '属性名称',
          align: 'center',
          dataIndex: 'propName',
        },
        {
          title: '属性说明',
          align: 'center',
          dataIndex: 'remark',
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'propType_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 167,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/dataProperty/dataProperty/list',
        delete: '/dataProperty/dataProperty/delete',
        deleteBatch: '/dataProperty/dataProperty/deleteBatch',
        exportXlsUrl: '/dataProperty/dataProperty/exportXls',
        importExcelUrl: 'dataProperty/dataProperty/importExcel',
        edit: '/dataProperty/dataProperty/edit',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: { status: '1' },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'propId', text: '属性id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'propNo', text: '属性编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'propName', text: '属性名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '属性说明', dictCode: '' })
      fieldList.push({ type: 'string', value: 'propType', text: '类型', dictCode: 'prop_type' })
      this.superFieldList = fieldList
    },
    onChange(record) {
      var that = this
      var param = Object.assign({}, record)
      param.status = record.status
      that.loading = true
      httpAction(this.url.edit, param, 'post')
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>